package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategorySaveDTO;
import com.sky.entity.Category;
import com.sky.result.Result;
import com.sky.service.impl.CategoryServiceImpl;
import com.sky.vo.CategoryVO;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/admin/category")
public class CategoryController {


    @Autowired
    private CategoryServiceImpl categoryServiceImpl;

    @GetMapping("/page")
    public Result page( CategoryDTO categoryDTO){

        CategoryVO result = categoryServiceImpl.page(categoryDTO);

        return Result.success(result);
    }

    @PostMapping
    public Result save(@RequestBody CategorySaveDTO categorysaveDTO){

        categoryServiceImpl.save(categorysaveDTO);
        return Result.success();
    }

    @PutMapping
    public Result update(@RequestBody CategorySaveDTO categorysaveDTO){

        categoryServiceImpl.update(categorysaveDTO);
        return Result.success();
    }

    @DeleteMapping
    public Result delete(@RequestParam String id){

        categoryServiceImpl.delete(id);
        return Result.success();
    }

    @PostMapping("/status/{status}")
    public Result status(@PathVariable String status,String id){

        categoryServiceImpl.status(status,id);
        return Result.success();
    }

    @GetMapping("list")
    public Result list(@RequestParam("type") String type){
        List<Category> list = categoryServiceImpl.list(type);
        return Result.success(list);
    }
}
